#include "cramer.hh"

float Cramer::determinante(float a[3][3]){
  return (a[0][0]*a[1][1]*a[2][2]) + (a[0][1]*a[1][2]*a[2][0]) + (a[0][2]*a[1][0]*a[2][1]) - ((a[2][0]*a[1][1]*a[0][2]) + (a[2][1]*a[1][2]*a[0][0]) + (a[2][2]*a[1][0]*a[0][1]));
}

Cramer::Cramer(float a[3][3], float b[3]){
  float det = determinante(a);
  std::cout << "Det: " << det << std::endl; 

  std::cout << "b1: " << b[0] << std::endl
	    << "b2: " << b[1] << std::endl
	    << "b3: " << b[2] << std::endl; 
  
  float tmp[3][3];

  for(int i = 0; i < 3; i++)
    for(int j = 0; j < 3; j++)
      tmp[i][j] = a[i][j]; 
  tmp[0][0] = b[0];
  tmp[1][0] = b[1];
  tmp[2][0] = b[2];
  float dx = determinante(tmp);
  
  for(int i = 0; i < 3; i++)
    for(int j = 0; j < 3; j++)
      tmp[i][j] = a[i][j];  
  tmp[0][1] = b[0];
  tmp[1][1] = b[1];
  tmp[2][1] = b[2];
  float dy = determinante(tmp);
  
  for(int i = 0; i < 3; i++)
    for(int j = 0; j < 3; j++)
      tmp[i][j] = a[i][j]; 
  tmp[0][2] = b[0];
  tmp[1][2] = b[1];
  tmp[2][2] = b[2];
  float dz = determinante(tmp);
  
  x = dx/det;
  y = dy/det;
  z = dz/det;

}

float Cramer::getX(){
  return x; 
}

float Cramer::getY(){
  return y; 
}

float Cramer::getZ(){
  return z; 
}
